package com.zqu.ordersystem.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置头像静态资源访问
        registry.addResourceHandler("/uploads/avatars/**")
                .addResourceLocations("file:d:/BaiduNetdiskDownload/ordering-system-master/Order-System/uploads/avatars/");
        // 配置食品图片静态资源访问
        registry.addResourceHandler("/uploads/dishes/**")
                .addResourceLocations("file:d:/BaiduNetdiskDownload/ordering-system-master/Order-System/uploads/dishes/");
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8888")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*")
                .allowCredentials(true)
                .maxAge(3600);
    }
}
